package com.linkhub.oms.admin.modules.logistic.rules.strategy.impl;

import com.linkhub.oms.admin.modules.logistic.rules.domain.ChannelRuleMatchRequest;
import com.linkhub.oms.admin.modules.logistic.rules.strategy.ChannelRuleMatchStrategy;
import com.linkhub.oms.common.enums.IEnumConvert;
import com.linkhub.oms.common.enums.logistic.ChannelDeliverableCountryEnum;
import com.linkhub.oms.common.util.QtOptionalUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;

/**
 * @Description: ChannelDeliverableCountryLimit
 * @Author: echo
 * @Date: 2024/6/1 15:36
 * @Version: 1.0
 */
@Slf4j
@Service
@Order(value = Ordered.HIGHEST_PRECEDENCE)
public class ChannelDeliverableCountryLimit extends BaseChannelRuleMatchStrategy implements ChannelRuleMatchStrategy {
    @Override
    public boolean match(ChannelRuleMatchRequest request) {
        String orderCountryCode = request.acquireOrderCountryCode();
        String channelCode = request.acquireChannelCode();
        ChannelDeliverableCountryEnum deliverableCountry = IEnumConvert.valueOf(channelCode, ChannelDeliverableCountryEnum.class);
        return QtOptionalUtil.of(deliverableCountry)
                .map(deliverable -> deliverable.getCountryCodes().contains(orderCountryCode))
                .orElse(Boolean.FALSE);

    }
}
